package com.chenyaowei.order.vo;

import cn.hutool.core.collection.CollectionUtil;
import com.chenyaowei.cart.bo.CartItemBO;
import com.chenyaowei.marketing.domain.CywCouponInfo;
import com.chenyaowei.member.domain.CywMemberReceiveAddress;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
import java.util.Set;

public class OrderConfirmVO implements Serializable
{
    private static final long serialVersionUID = 1L;

    /** 收货地址 */
    List<CywMemberReceiveAddress> addressList;

    /** 所以选中的购物项 */
    List<CartItemBO> items;

    /** 防重令牌 */
    String orderToken;

    /** 用户购物积分 */
    Integer integration;

    /** 优惠券信息 */
    Set<CywCouponInfo> couponList;

    /** 优惠券信息 */
    BigDecimal couponDiscount;

    public BigDecimal getCouponDiscount() {
        return couponDiscount;
    }

    public void setCouponDiscount(BigDecimal couponDiscount) {
        this.couponDiscount = couponDiscount;
    }

    public Set<CywCouponInfo> getCouponList() {
        return couponList;
    }

    public void setCouponList(Set<CywCouponInfo> couponList) {
        this.couponList = couponList;
    }

    public List<CywMemberReceiveAddress> getAddressList() {
        return addressList;
    }

    public void setAddressList(List<CywMemberReceiveAddress> addressList) {
        this.addressList = addressList;
    }

    public List<CartItemBO> getItems() {
        return items;
    }

    public void setItems(List<CartItemBO> items) {
        this.items = items;
    }

    public String getOrderToken() {
        return orderToken;
    }

    public void setOrderToken(String orderToken) {
        this.orderToken = orderToken;
    }

    public Integer getIntegration() {
        return integration;
    }

    public void setIntegration(Integer integration) {
        this.integration = integration;
    }

    /** 商品总件数 */
    public Integer getCount() {
        Integer i = 0;
        if (CollectionUtil.isNotEmpty(items)){
            for (CartItemBO item : items) {
                i += item.getCount();
            }
        }
        return i;
    }

    /** 订单总额 */
    public BigDecimal getTotal() {
        BigDecimal sum = new BigDecimal("0");
        if (CollectionUtil.isNotEmpty(items)){
            for (CartItemBO item : items) {
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount()));
                sum = sum.add(multiply);
            }
        }
        return sum;
    }


    /** 应付价格 */
    public BigDecimal getPayPrice()  {
    return getTotal().subtract(getTotalDiscount() == null? new BigDecimal("0") : getTotalDiscount());
}

    /** 优惠价格 */
    public BigDecimal getTotalDiscount()  {
        return getCouponDiscount();
    }
}
